<template>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getIndexCommodityList">
        <store-list :storeList="storeList"></store-list>
    </van-list>
</template>

<script>
import store from '@/api/store'
import StoreList from './StoreList.vue'

export default {
    components: {
        StoreList
    },
    data() {
        return {
            storeList: [],
            finished: false,
            loading: false,
        }
    },
    computed: {
        getLongitude() {
            return this.$store.state.location.longitude
        },
        getLatitude() {

            return this.$store.state.location.latitude
        }
    },
    watch: {
        getLongitude(val) {
            console.log("getLongitude")
            this.getIndexCommodityList()
        },
        getLatitude(val) {
            // console.log("getLatitude")
            // this.getIndexCommodityList()
        }
    },
    created() {
        this.getIndexCommodityList()
    },
    methods: {
        getIndexCommodityList() {
            let longitude = this.getLongitude
            let latitude = this.getLatitude
            let data = {
                longitude,
                latitude
            }

            if (this.getLongitude && this.getLatitude)
                store.getStore(data)
                    .then(res => {
                        if (res.code == 200) {
                            // this.storeList = this.storeList.concat(res.data.storeList)
                            this.storeList = res.data.storeList

                            this.loading = false
                            this.finished = true
                        } else {
                            this.$toast(res.message)
                        }
                    })


            else this.$toast("请定位")
        }
    }
}
</script>
